package com.example.administrator.encryptiondemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class MainActivity extends AppCompatActivity {

    private String path = "http://api.m.mtime.cn/Showtime/LocationMovies.api?locationId=";
    //毛泽东 =
    private String url1 = "http://baike.so.com/doc/1184930-1253444.html";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //URLEncode编码
        String encode = null;
        try {
            encode = URLEncoder.encode("毛泽东","UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Log.d("1608","进行URLEncode之后的内容："+ encode);
        //使用URLDecoder进行解码
        String str = "";
        String decode = null;
        try {
            decode = URLDecoder.decode(str,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Log.d("1608","进行URLDecoder之后的内容："+ decode);
        //path = path+ encode+"s";
        new Thread(new Runnable() {
            @Override
            public void run() {
                InputStream is = null;
                ByteArrayOutputStream baos = null;
                try {
                    URL url = new URL(url1);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setConnectTimeout(3000);
                    if (conn.getResponseCode() == 200){
                        InputStream inputStream = conn.getInputStream();
                        byte[] buf = new byte[1024*1024];
                    }
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }).start();
    }
}
